//
//  XDTeacherCommentViewController.m
//  XDEducation
//
//  Created by apple on 2017/4/19.
//  Copyright © 2017年 apple. All rights reserved.
//

#import "XDTeacherCommentViewController.h"
#import "XDCommentNoonModel.h"
#import "XDTeacherCommentDetailsViewController.h"
@interface XDTeacherCommentViewController ()
/** 午托数据源 */
@property(nonatomic,strong) NSMutableArray *commentNoonModelArr;
@end

@implementation XDTeacherCommentViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    if ([self.title isEqualToString:@"午托评语"]) {
        
        self.commentType = CommentTypeNoon;
        
    }else if([self.title isEqualToString:@"晚辅评语"]){
        
        self.commentType = CommentTypeNight;
        
    }else if([self.title isEqualToString:@"作业评语"]){
        
        self.commentType = CommentTypeHomeWork;
    }
    
    [self initNetworkingWithRefreshStatus:RefreshStatePullDown];
    
}

/*
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    return self.commentNoonModelArr.count;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 60 * ScaleHeight;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellId = @"cellId";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
    }
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    XDCommentNoonModel *model = self.commentNoonModelArr[indexPath.row];
    cell.textLabel.text = [NSString stringWithFormat:@"%@",model.title];
    cell.textLabel.textColor = UIColorFromRGB(0x4c4c4c);
    cell.textLabel.font = [UIFont systemFontOfSize:15];
    return cell;
}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    XDTeacherCommentDetailsViewController *vc = [[XDTeacherCommentDetailsViewController alloc]init];
    vc.title = self.title;
    [self.navigationController pushViewController:vc animated:YES];
}
*/

-(void)initNetworkingWithRefreshStatus:(RefreshState)status{
    
    NSString *url;
    NSDictionary *dict;

    switch (self.commentType) {
        case CommentTypeNoon:{
           
            url = BaseURL(@"aflatunLesson.do?action=getCommentTitle");
            dict = @{@"bigType":@1,@"pageNumber":@(self.pageNumber)};
        }
            break;
        case CommentTypeNight:{
            url = BaseURL(@"aflatunLesson.do?action=getCommentTitle");
            dict = @{@"pageNumber":@(self.pageNumber)};
        }
            break;
        case CommentTypeHomeWork:{
            url = BaseURL(@"homework.do?action=getRemarkInfo");
            dict = @{@"pageNumber":@(self.pageNumber),@"uid":[AccountTool shareAccountTool].currentAccount.uid,@"type":@5};//
            
            
//        http://192.168.0.107:8080/StarShine/ws/homework.do
//            [uid=257 | action=getRemarkInfo | pageNumber=1 | type=5]
        }
            break;
        default:
            break;
    }
    
    [MBProgressHUD showHUD];
    [XDHttpTool get:url authCode:[AccountTool shareAccountTool].currentAccount.authCode params:dict success:^(id responseObj) {
        [MBProgressHUD hideHUD];
        
        
        if (self.commentType == CommentTypeHomeWork) {
            NSArray *arr = responseObj;
            NSLog(@"%@",responseObj);
            if(arr.count == 0){
                [MBProgressHUD showError:XDNoMoreData];
                return ;
            }else{
            
                NSLog(@"未实现");
                return;
            }
        }
       
            
        NSArray *dictArr = [[responseObj objectForKey:@"t"] objectForKey:@"dataList"];
        NSMutableArray *tempArr = [NSMutableArray array];
        
        for (NSDictionary *dict in dictArr) {
            XDCommentNoonModel *model = [XDCommentNoonModel commentNoonModelWith:dict];
            [tempArr addObject:model];
        }
        self.commentNoonModelArr = tempArr;
        [self.tableView reloadData];
        
    } failure:^(NSError *error) {
        [MBProgressHUD hideHUD];
        [MBProgressHUD showError:XDNetWorkError];
        NSLog(@"%@",error);
        
    }];
    
}

@end
